﻿using Estsh.Core.Model.EnumUtil;
using Estsh.Core.Model.Result;
using Estsh.Core.Models;
using Estsh.Core.Quartz.BaseService;
using Estsh.Core.Util;
using Estsh.Core.Wms.IRepositories;

namespace Estsh.Core.Wms.Jobs
{
    /// <summary>
    ///WMS将每次发运的信息传递给SAP,SAP用于对交货单发货。
    /// </summary>
    public class WMSSalesAndDeliveryPlanJob : IJobService
    {
        private readonly IWMSInterfaceMasterRepository repository;


        public WMSSalesAndDeliveryPlanJob(IWMSInterfaceMasterRepository _repository)
        {
            this.repository = _repository;

        }

        public string ExecuteService(string parameter)
        {
            try
            {
                List<WmsNjsiInterface> wmsNjsis = repository.GetSalesAndDeliveryPlansInfo();
                if (wmsNjsis.Count <= 0)
                {
                    return "没有待处理的销售发货结果非JIS信息！";
                }

                SapInterfaceResult result = repository.InsertSalesAndDeliveryPlanInfo(wmsNjsis);
                return result.message;
            }
            catch (Exception ex)
            {
                LogHelper.Error("销售发货结果非JIS接口错误！" + ex);
                return "销售发货结果非JIS接口错误！" + ex.Message;
            }
        }
    }
}
